package com.purong.purong.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.PercentFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.purong.purong.Contant;
import com.purong.purong.PermissionConstant;
import com.purong.purong.PuRongApp;
import com.purong.purong.R;
import com.purong.purong.adapter.LoanDetQuestionAdapter;
import com.purong.purong.adapter.LoanQuestionAdapter;
import com.purong.purong.bean.PeriodBean;
import com.purong.purong.bean.QuestionBean;
import com.purong.purong.bean.SmallLoanBean;
import com.purong.purong.bean.SmallLoanDetBean;
import com.purong.purong.bean.SmallLoanQuestListBean;
import com.purong.purong.util.CommonUtil;
import com.purong.purong.util.ComputeUtil;
import com.purong.purong.util.SharePreUtil;
import com.purong.purong.widget.AdjustSizeRelativeLayout;
import com.purong.purong.widget.FullyLinearLayoutManager;
import com.purong.purong.widget.GradationScrollView;
import com.purong.purong.widget.JustifyTextView;
import com.purong.purong.widget.LoadingView;
import com.purong.purong.widget.PeriodDialog;
import com.purong.purong.widget.RadiusImageView;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.yao.sdk.glide.GlideUtil;
import com.yao.sdk.net.ResponseInfo;
import com.yaoming.umengshare.SharePlatform;
import com.yaoming.umengshare.UmShare;
import com.yaoming.umengshare.listener.ShareResultListener;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import me.grantland.widget.AutofitTextView;

/**
 * Created by wenjiezeng on 2017/11/1.
 */
public class SmallLoanDetialActivity extends BasePermActivity implements OnChartValueSelectedListener,GradationScrollView.ScrollViewListener {
    private PieChart mPieChart;
    private AdjustSizeRelativeLayout mainLay;
    private GradationScrollView mScrollView;
    private RelativeLayout titleBar;
    private ImageView back,flowImg,editImg,favoriteImg;
    private View titleCutLine;
    private EditText loanMoneyEd;
    private RadiusImageView loanImg;
    private AutofitTextView moneyRange;
    private JustifyTextView fysmTv,hkfsTv,tqhkTv,yqzcTv;
    private TextView title,periodTv,name,outLine,rate,loanInfo,loanRate;
    private int titlebarRange,titleTxRange;
    private PeriodDialog mPeriodDialog;
    private RecyclerView questRecyclerView;
    private List<PeriodBean> periodList = new ArrayList<>();
    private List<QuestionBean> questList = new ArrayList<>();
    private LoanDetQuestionAdapter mQuestAdapter;
    private PeriodBean mPeriod;
    private LoadingView mLoadingView;
    private SmallLoanBean mLoan;
    private SmallLoanDetBean loanDetBean;
    private boolean needBack;
    @Override
    public void finish() {
        if (needBack&&loanDetBean!=null){
            Intent intent=new Intent();
            intent.putExtra("LOAN",loanDetBean);
            setResult(RESULT_OK,intent);
        }
        super.finish();
    }
    @Override
    public void initBundle() {
        mLoan=(SmallLoanBean) getIntent().getSerializableExtra("LOAN");
        needBack=getIntent().getBooleanExtra("NEED_BACK",false);
    }

    @Override
    public void initView() {
        mLoadingView =(LoadingView)findViewById(R.id.loading_view);
        mLoadingView.setLoadListener(new LoadingView.OnLoadListener() {
            @Override
            public void onReload() {
                if (mLoan!=null){
                    getLoanDet();
                    getQuestion();
                }
            }

            @Override
            public void onRefresh() {

            }
        });
        mainLay=(AdjustSizeRelativeLayout)findViewById(R.id.main_lay);
        mainLay.setSoftKeyBoardListener(new AdjustSizeRelativeLayout.SoftkeyBoardListener() {
            @Override
            public void keyBoardVisable(int move) {
                editImg.setVisibility(View.INVISIBLE);
                Log.e("zwj","..键盘弹出");
            }

            @Override
            public void keyBoardInvisable(int move) {
                editImg.setVisibility(View.VISIBLE);
                String loanString = loanMoneyEd.getText().toString().trim();
                if (loanString == null || loanString.equals("") ||
                        Integer.valueOf(loanString) < Integer.valueOf(loanDetBean.getMin_small_money())) {
                    loanString = loanDetBean.getMin_small_money();

                } else if (Integer.valueOf(loanString) > Integer.valueOf(loanDetBean.getMax_small_money())) {
                    loanString = loanDetBean.getMax_small_money();
                }
                loanMoneyEd.setText(loanString);
                loanMoneyEd.clearFocus();
                loadCompute();
                Log.e("zwj","..键盘隐藏");
            }
        });
        titlebarRange=CommonUtil.dip2px(this,80);
        titleTxRange=(int)(titlebarRange*0.3);
        //饼状图
        mPieChart = (PieChart) findViewById(R.id.pie_chart);
        initPieChart();
        loanMoneyEd=(EditText)findViewById(R.id.loan_money_edit);

        loanMoneyEd.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s.toString().startsWith("0")) {
                    loanMoneyEd.setText(s.toString().replaceFirst("0", ""));
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        titleBar=(RelativeLayout)findViewById(R.id.title_bar);
        titleCutLine=(View)findViewById(R.id.title_cut_line);
        back=(ImageView)findViewById(R.id.left_back);
        periodTv=(TextView)findViewById(R.id.period_tv);
        title=(TextView)findViewById(R.id.title);
        if (mLoan!=null&&mLoan.getSmall_product_name()!=null){
            title.setText(mLoan.getSmall_product_name());
        }
        mScrollView = (GradationScrollView) findViewById(R.id.scroll_view);
        mScrollView.setScrollViewListener(this);
        flowImg=(ImageView)findViewById(R.id.flow_img);
        flowImg.setLayoutParams(new LinearLayout.LayoutParams((int)(CommonUtil.dip2px(this,46)*9.44), CommonUtil.dip2px(this,46)));
        fysmTv=(JustifyTextView)findViewById(R.id.fysm_tv);
        hkfsTv=(JustifyTextView)findViewById(R.id.hkfs_tv);
        tqhkTv=(JustifyTextView)findViewById(R.id.tqhk_tv);
        yqzcTv=(JustifyTextView)findViewById(R.id.yqzc_tv);
        favoriteImg = (ImageView) findViewById(R.id.favorite_img);
        name=(TextView)findViewById(R.id.name);
        outLine=(TextView)findViewById(R.id.outline);
        moneyRange=(AutofitTextView)findViewById(R.id.money_range);
        rate=(TextView)findViewById(R.id.rate);
        loanInfo=(TextView)findViewById(R.id.loan_info);
        loanRate=(TextView)findViewById(R.id.loan_rate);
        loanImg=(RadiusImageView) findViewById(R.id.loan_img);
        editImg=(ImageView) findViewById(R.id.edit_img);
        questRecyclerView = (RecyclerView) findViewById(R.id.question_recycler_view);
        questRecyclerView.setLayoutManager(new FullyLinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        mQuestAdapter = new LoanDetQuestionAdapter(this);
        mQuestAdapter.setData(questList);
        mQuestAdapter.setOnLoanQuestionListener(new LoanDetQuestionAdapter.OnLoanQuestionListener() {
            @Override
            public void onQuestionClick(QuestionBean bean) {
                Intent intent=new Intent(SmallLoanDetialActivity.this,HelpQuestDetActivity.class);
                intent.putExtra("QUESTION",bean);
                startActivity(intent);
            }
        });
        questRecyclerView.setAdapter(mQuestAdapter);
    }

    @Override
    public void initData() {
        if (mLoan != null) {
            getLoanDet();
            getQuestion();
        }

    }

    @Override
    public int getRootViewId() {
        return R.layout.activity_small_loan_detial;
    }
    private void getLoanDet(){
        mLoadingView.loading();
        Map<String, String> params = new LinkedHashMap<String, String>();
        params.put("small_id",mLoan.getSmall_product_id());
        if (!request(Contant.SMALL_DETAILS, params, true, false)){
            mLoadingView.fail();
        }
    }
    private void getQuestion() {
        Map<String, String> params = new LinkedHashMap<String, String>();
        params.put("small_agency_id", mLoan.getSmall_agency_id());
        request(Contant.SMALL_QUESTION, params, true, false);
    }
    private void setShare(String platform) {
        Map<String, String> params = new LinkedHashMap<String, String>();
        if (platform.equals("WEIXIN")){
            params.put("share_type", "1");
        }else if (platform.equals("WEIXIN_CIRCLE")){
            params.put("share_type", "2");
        }else if (platform.equals("QQ")){
            params.put("share_type", "3");
        }
        params.put("small_product_id", loanDetBean.getSmall_product_id());
        request(Contant.SMALL_SHARE_LOG, params, true, false);
    }
    private void setFavourite() {
        Map<String, String> params = new LinkedHashMap<String, String>();
        params.put("small_id", loanDetBean.getSmall_product_id());
        request(Contant.SMALL_FAVORITE, params, true, true);
    }
    private void apply() {
        Map<String, String> params = new LinkedHashMap<String, String>();
        params.put("small_id", loanDetBean.getSmall_product_id());
        params.put("province_id", SharePreUtil.getInstance(this).getLoactionParentId());
        params.put("city_id", SharePreUtil.getInstance(this).getLoactionAreaId());
        params.put("apply_money", loanMoneyEd.getText().toString().trim());
        params.put("apply_period", mPeriod.getPeriod_id());
        request(Contant.SMALL_APPLY, params, true, true);
    }
    private void cancelFavourite() {
        Map<String, String> params = new LinkedHashMap<String, String>();
        params.put("small_id", loanDetBean.getSmall_product_id());
        request(Contant.SMALL_FAVORITE_CANCEL, params, true, true);
    }

    private void setData(){
        if (loanDetBean==null)
            return;
        setPeriod();
        GlideUtil.getInstance().load(this,loanDetBean.getSmall_product_url(),loanImg,true);
        title.setText(loanDetBean.getSmall_product_name());
        name.setText(loanDetBean.getSmall_product_name());
        outLine.setText(loanDetBean.getSmall_product_outline());
        loanMoneyEd.setText(loanDetBean.getMin_small_money());
        rate.setText(CommonUtil.formatDouble(mPeriod.getRate())+"%");
        periodTv.setText(mPeriod.getPeriod_name());
        moneyRange.setText(CommonUtil.numConvertSubZero(Integer.valueOf(loanDetBean.getMin_small_money()),2)+"~"+ CommonUtil.numConvertSubZero(Integer.valueOf(loanDetBean.getMax_small_money()),2));
        if (loanDetBean.getSmall_fee_str()!=null&&!loanDetBean.getSmall_fee_str().equals("")){
            findViewById(R.id.fysm_title).setVisibility(View.VISIBLE);
            findViewById(R.id.fysm_cut_line).setVisibility(View.VISIBLE);
            findViewById(R.id.fysm_lay).setVisibility(View.VISIBLE);
            fysmTv.setVisibility(View.VISIBLE);
            fysmTv.setText(loanDetBean.getSmall_fee_str());
        }
        boolean showHksm=false;
        if (loanDetBean.getSmall_repayment_mode()!=null&&!loanDetBean.getSmall_repayment_mode().equals("")){
            findViewById(R.id.hkfs_title).setVisibility(View.VISIBLE);
            hkfsTv.setVisibility(View.VISIBLE);
            hkfsTv.setText(loanDetBean.getSmall_repayment_mode());
            showHksm=true;
        }
        if (loanDetBean.getSmall_repayment_advance()!=null&&!loanDetBean.getSmall_repayment_advance().equals("")){
            findViewById(R.id.tqhk_title).setVisibility(View.VISIBLE);
            tqhkTv.setVisibility(View.VISIBLE);
            tqhkTv.setText(loanDetBean.getSmall_repayment_advance());
            showHksm=true;
        }
        if (loanDetBean.getSmall_repayment_overdue()!=null&&!loanDetBean.getSmall_repayment_overdue().equals("")){
            findViewById(R.id.yqzc_title).setVisibility(View.VISIBLE);
            yqzcTv.setVisibility(View.VISIBLE);
            yqzcTv.setText(loanDetBean.getSmall_repayment_overdue());
            showHksm=true;
        }
        if (showHksm){
            findViewById(R.id.hksm_title).setVisibility(View.VISIBLE);
            findViewById(R.id.hksm_lay).setVisibility(View.VISIBLE);
            findViewById(R.id.hksm_cut_line).setVisibility(View.VISIBLE);
        }
        if (loanDetBean.getIs_favorite().equals("1")) {
            favoriteImg.setImageResource(R.drawable.cart_icon_collect);
        } else {
            favoriteImg.setImageResource(R.drawable.nav_icon_collect_sel);
        }
        loadCompute();
    }
    private void share() {
        UmShare share = new UmShare(this, new ShareResultListener() {
            @Override
            public void onStart(String platform) {
                setShare(platform);
            }

            @Override
            public void onSuccess(String platform) {
            }

            @Override
            public void onCancel(String platform) {
            }

            @Override
            public void onError(String platform, Throwable t) {
            }
        });
        if (loanDetBean.getSmall_product_url() != null && !loanDetBean.getSmall_product_url().equals("")) {
            share.setImage(loanDetBean.getSmall_product_url());
        } else {
            share.setImage(R.mipmap.app_icon);
        }
        share.setText("普融信贷超市—全网唯一全额贴息互联网金融超市，日均贴息10万元。");
        share.setTitle("普融—中国中小企业普惠金融O2O模式领导者");
        if (loanDetBean.getShare_url() != null && loanDetBean.getShare_url().startsWith("http")) {
            share.setTargetUrl(loanDetBean.getShare_url());
        } else {
            share.setTargetUrl("http://www.purong.com/");
        }
        share.setPlatform(new SharePlatform(SHARE_MEDIA.WEIXIN), new SharePlatform(SHARE_MEDIA.WEIXIN_CIRCLE), new SharePlatform(SHARE_MEDIA.QQ));
        share.share();
    }
    private void loadCompute() {
        if (loanDetBean == null)
            return;
        int loanMoney = Integer.valueOf(loanMoneyEd.getText().toString().trim());
        String rate = ComputeUtil.smallLoanRate(loanMoney, Double.valueOf(mPeriod.getRate()), Integer.valueOf(mPeriod.getPeriod_id()));
        loanInfo.setText("到账金额: " +loanMoney+"元");
        loanRate.setText("利息和费用: "+rate+"元");
        float total = (float) loanMoney + Float.valueOf(rate);
        float ratePie = Float.valueOf(rate) / total * 100;
        float loanPie = 100 - ratePie ;
        showPie(loanPie, ratePie);
    }
    private void setPeriod() {
        if (loanDetBean == null||loanDetBean.getPeriod_rate_info()==null)
            return;
        periodList.clear();
        PeriodBean period;
        for (int i = 0; i <loanDetBean.getPeriod_rate_info().size() ; i++) {
            period = new PeriodBean();
            period.setPeriod_id(loanDetBean.getPeriod_rate_info().get(i).getPeriod());
            period.setPeriod_name(loanDetBean.getPeriod_rate_info().get(i).getPeriod()+"个月");
            period.setRate(loanDetBean.getPeriod_rate_info().get(i).getRate());
            periodList.add(period);
        }
        if (periodList.size() == 0) {
            period = new PeriodBean();
            period.setPeriod_id("0");
            period.setPeriod_name("0个月");
            period.setRate("0");
            periodList.add(period);
        }
        mPeriod = periodList.get(0);
    }
    private void initPieChart(){
        // 设置饼图是否接收点击事件，默认为true
        mPieChart.setTouchEnabled(false);
        mPieChart.setUsePercentValues(true);
        mPieChart.getDescription().setEnabled(false);
        mPieChart.setExtraOffsets(0, 0, 0, 0);
        mPieChart.setDragDecelerationFrictionCoef(0.95f);
        //设置中间文件
        mPieChart.setCenterText("");
        mPieChart.setDrawCenterText(false);

        mPieChart.setDrawHoleEnabled(true);
        //设置中间圆盘的颜色
        mPieChart.setHoleColor(getResources().getColor(R.color.transparent));

        mPieChart.setTransparentCircleColor(getResources().getColor(R.color.blue));
        mPieChart.setTransparentCircleAlpha(110);
        //设置中间圆盘的半径,值为所占饼图的百分比
        mPieChart.setHoleRadius(60f);
        //设置中间透明圈的半径,值为所占饼图的百分比
        mPieChart.setTransparentCircleRadius(60f);
        //起始角度
        mPieChart.setRotationAngle(-90);
        // 触摸旋转
        mPieChart.setRotationEnabled(false);
        mPieChart.setHighlightPerTapEnabled(true);
        //变化监听
        mPieChart.setOnChartValueSelectedListener(this);
        mPieChart.setDrawSliceText(false);
        mPieChart.highlightValues(null);
        //设置数据

        //设置比例图
        Legend l = mPieChart.getLegend();
        l.setEnabled(false);
        //刷新

        // 输入标签样式
//        mPieChart.setEntryLabelColor(getResources().getColor(R.color.blue));
//        mPieChart.setEntryLabelTextSize(12f);
    }
    private void showPie(float loan, float rate){
        if (mPieChart==null)
            return;
        mPieChart.setData(getPieData(loan,rate));
        mPieChart.invalidate();
        mPieChart.animateY(1000, Easing.EasingOption.EaseInOutQuad);
    }
    private PieData getPieData(float i,float j) {
        //模拟数据
        ArrayList<PieEntry> entries = new ArrayList<PieEntry>();
        entries.add(new PieEntry(i, ""));
        entries.add(new PieEntry( j, ""));
        PieDataSet dataSet = new PieDataSet(entries, "");
        //设置各个饼状图之间的距离
        dataSet.setSliceSpace(0f);
        // 部分区域被选中时多出的长度
        dataSet.setSelectionShift(0f);

        //数据和颜色
        ArrayList<Integer> colors = new ArrayList<Integer>();
        colors.add(getResources().getColor(R.color.blue));
        colors.add(getResources().getColor(R.color.orange));
        dataSet.setColors(colors);
        PieData data = new PieData(dataSet);
        data.setValueFormatter(new PercentFormatter());
        data.setValueTextSize(11f);
        data.setValueTextColor(getResources().getColor(R.color.transparent));
        return data;
    }
    @Override
    public void onValueSelected(Entry e, Highlight h) {

    }

    @Override
    public void onNothingSelected() {

    }
    private void initPeriodDialog() {
        mPeriodDialog = new PeriodDialog(this, periodList, new PeriodDialog.OnRefundReasonListener() {
            @Override
            public void onCancel() {

            }

            @Override
            public void onSelect(PeriodBean period) {
                if (period != null) {
                    mPeriod = period;
                    periodTv.setText(period.getPeriod_name());
                    rate.setText(CommonUtil.formatDouble(period.getRate())+"%");
                    loadCompute();
                }

            }
        });

    }

    @Override
    public void onResponse(ResponseInfo responseInfo) {
        if (hasDestroy())
            return;
        super.onResponse(responseInfo);
        if (responseInfo.url.equals(Contant.SMALL_DETAILS)) {
            if (responseInfo.isRequestOk) {
                try {
                    loanDetBean=JSON.parseObject(responseInfo.content,SmallLoanDetBean.class);
                    if (loanDetBean!=null){
                        setData();
                        mLoadingView.finish();
                    }else {
                        mLoadingView.fail();
                    }
                } catch (Exception e) {
                    mLoadingView.fail();
                }

            }else {
                mLoadingView.fail();
            }
        }else if (responseInfo.url.equals(Contant.SMALL_QUESTION)) {
            if (responseInfo.isRequestOk) {
                try {
                    SmallLoanQuestListBean questionBean = JSON.parseObject(responseInfo.content, SmallLoanQuestListBean.class);
                    if (questionBean != null && questionBean.getSmall_question_list() != null && questionBean.getSmall_question_list().size() > 0) {
                        questList.clear();
                        questList.addAll(questionBean.getSmall_question_list());
                        mQuestAdapter.notifyDataSetChanged();
                        findViewById(R.id.question_lay).setVisibility(View.VISIBLE);
                    } else {
                        findViewById(R.id.question_lay).setVisibility(View.GONE);

                    }

                } catch (Exception e) {

                }
            } else {

            }
        }else if (responseInfo.url.equals(Contant.SMALL_FAVORITE)) {
            if (responseInfo.isRequestOk) {
                showToast("已收藏");
                favoriteImg.setImageResource(R.drawable.nav_icon_collect_sel);
                loanDetBean.setIs_favorite("2");
            }
        } else if (responseInfo.url.equals(Contant.SMALL_FAVORITE_CANCEL)) {
            if (responseInfo.isRequestOk) {
                showToast("已取消收藏");
                favoriteImg.setImageResource(R.drawable.cart_icon_collect);
                loanDetBean.setIs_favorite("1");
            }
        }else if (responseInfo.url.equals(Contant.SMALL_APPLY)) {
            if (responseInfo.isRequestOk) {
                Intent intent=new Intent(this,WebActivity.class);
                intent.putExtra("TITLE", loanDetBean.getSmall_product_name());
                intent.putExtra("URL", loanDetBean.getSmall_apply_url());
                intent.putExtra("TITLEBAR", true);
                startActivity(intent);
            }
        }
    }

    public void onClick(View v){
        switch (v.getId()){
            case R.id.apply:
                if (loanDetBean == null)
                    return;
                String loanString = loanMoneyEd.getText().toString().trim();
                if (loanString.equals("")){
                    showToast("请输入贷款金额");
                    return;
                }
                if (Integer.valueOf(loanString) < Integer.valueOf(loanDetBean.getMin_small_money())
                        ||Integer.valueOf(loanString) > Integer.valueOf(loanDetBean.getMax_small_money())){
                    showToast("贷款金额必须在额度范围内");
                    return;
                }
                if (PuRongApp.getLoginInfo(this) != null) {
                    apply();
                }else {
                    Intent intent=new Intent(this,LoginActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.more_question:
                if (loanDetBean == null)
                    return;
                Intent intent=new Intent(this,LoanQuestionActivity.class);
                intent.putExtra("AGENCY_ID", loanDetBean.getSmall_agency_id());
                startActivity(intent);
                break;
            case R.id.load_period:
                if (mPeriodDialog == null) {
                    initPeriodDialog();
                    mPeriodDialog.show();
                } else {
                    mPeriodDialog.show();
                }
                break;
            case R.id.favorite:
                if (loanDetBean != null && loanDetBean.getIs_favorite().equals("1")) {
                    setFavourite();
                } else {
                    cancelFavourite();
                }
                break;
            case R.id.share:
                if (Build.VERSION.SDK_INT >= 23) {
                    checkPermission();
                } else {
                    share();
                }
                break;
            case R.id.edit_lay:
                if (!loanMoneyEd.hasFocus())
                    loanMoneyEd.requestFocus();
                loanMoneyEd.setSelection(loanMoneyEd.getText().toString().trim().length());
                InputMethodManager imm = (InputMethodManager) loanMoneyEd.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
                break;
            case R.id.left_back:
                finish();
                break;
        }
    }
    @Override
    public void onScrollChanged(GradationScrollView scrollView, int x, int y, int oldx, int oldy) {
        if (y <= 0) {   //设置标题的背景颜色
            title.setTextColor(Color.argb((int) 255, 255, 255, 255));
            titleBar.setBackgroundColor(Color.argb((int) 0, 255, 255, 255));
            titleCutLine.setVisibility(View.GONE);
            back.setImageResource(R.drawable.icon_white_back);
        } else if (y > 0 && y <= titlebarRange) { //滑动距离小于banner图的高度时，设置背景和字体颜色颜色透明度渐变
            float scale = (float) y / titlebarRange;
            float alpha = (255 * scale);
            titleBar.setBackgroundColor(Color.argb((int) alpha, 255, 255, 255));
            if (y>titleTxRange){
                title.setTextColor(Color.argb((int) 255, 0,0, 0));
                titleCutLine.setVisibility(View.VISIBLE);
                back.setImageResource(R.drawable.icon_black_back);

            }else {
                title.setTextColor(Color.argb((int) 255, 255, 255, 255));
                titleCutLine.setVisibility(View.GONE);
                back.setImageResource(R.drawable.icon_white_back);

            }

        } else {    //滑动到banner下面设置普通颜色
            titleBar.setBackgroundColor(Color.argb((int) 255, 255, 255, 255));
            title.setTextColor(Color.argb((int) 255, 0,0, 0));
            titleCutLine.setVisibility(View.VISIBLE);
            back.setImageResource(R.drawable.icon_black_back);

        }

    }

    @Override
    protected String[] getPermissions() {
        return PermissionConstant.PERMS_STORAGE;
    }

    @Override
    protected void doPermissinosSuc() {
        share();
    }
}
